package com.example.controller;

import com.example.entity.Goods;
import com.example.entity.GoodsVo;
import com.example.service.GoodsService;
import com.example.vo.RespBeanEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@Slf4j
public class SeckillController {
    @Autowired
    GoodsService goodsService;

    @RequestMapping(value = "/doSeckill", method = RequestMethod.POST)

    public String doSeckill(Model model, int goodsId) {
        //log.info("商品编号 ：======"+goodsId);
        GoodsVo goods = goodsService.findGoodsVoByID(goodsId);
        //log.info(goods +"");
        int count = goods.getStock_count();
        if (count <= 0) {
            model.addAttribute("msg", RespBeanEnum.EMPTY_ERROR.getMessage());
            return ("fail");
        }

        model.addAttribute("msg", RespBeanEnum.EMPTY_ERROR.getMessage());
        return "ok";
    }
}
